package com.yic.module.device.dal.mysql.device;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.device.dal.dataobject.device.DeviceDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.device.controller.admin.device.vo.*;

/**
 * 设备基本信息 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface DeviceMapper extends BaseMapperX<DeviceDO> {

    default PageResult<DeviceDO> selectPage(DevicePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceDO>()
                .likeIfPresent(DeviceDO::getName, reqVO.getName())
                .likeIfPresent(DeviceDO::getCode, reqVO.getCode())
                .eqIfPresent(DeviceDO::getSn, reqVO.getSn())
                .eqIfPresent(DeviceDO::getMac, reqVO.getMac())
                .eqIfPresent(DeviceDO::getCategoryId, reqVO.getCategoryId())
                .eqIfPresent(DeviceDO::getSupplierId, reqVO.getSupplierId())
                .eqIfPresent(DeviceDO::getBrandId, reqVO.getBrandId())
                .eqIfPresent(DeviceDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(DeviceDO::getCenterId, reqVO.getCenterId())
                .eqIfPresent(DeviceDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DeviceDO::getUseStatus, reqVO.getUseStatus())
                .orderByDesc(DeviceDO::getId));
    }

    default List<DeviceDO> selectList(DeviceExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeviceDO>()
                .likeIfPresent(DeviceDO::getName, reqVO.getName())
                .likeIfPresent(DeviceDO::getCode, reqVO.getCode())
                .eqIfPresent(DeviceDO::getSn, reqVO.getSn())
                .eqIfPresent(DeviceDO::getMac, reqVO.getMac())
                .eqIfPresent(DeviceDO::getCategoryId, reqVO.getCategoryId())
                .eqIfPresent(DeviceDO::getSupplierId, reqVO.getSupplierId())
                .eqIfPresent(DeviceDO::getBrandId, reqVO.getBrandId())
                .eqIfPresent(DeviceDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(DeviceDO::getCenterId, reqVO.getCenterId())
                .eqIfPresent(DeviceDO::getUserId, reqVO.getUserId())
                .eqIfPresent(DeviceDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DeviceDO::getUseStatus, reqVO.getUseStatus())
                .orderByDesc(DeviceDO::getId));
    }

    default DeviceDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<DeviceDO>()
                .eq(DeviceDO::getCode, code));
    }

    default List<DeviceDO> selectList(Collection<Long> ids, Collection<Integer> statuses) {
        return selectList(new LambdaQueryWrapperX<DeviceDO>()
                .inIfPresent(DeviceDO::getId, ids)
                .inIfPresent(DeviceDO::getStatus, statuses));
    }

    default int updatePartById(DeviceDO deviceDO){
        return update(deviceDO, new LambdaUpdateWrapper<DeviceDO>()
                .set(DeviceDO::getUserId, deviceDO.getUserId())
                .set(DeviceDO::getLoacation, deviceDO.getLoacation())
                .set(DeviceDO::getDeptId, deviceDO.getDeptId())
                .set(DeviceDO::getFactoryId, deviceDO.getFactoryId())
                .set(DeviceDO::getCenterId, deviceDO.getCenterId())
                .set(DeviceDO::getUseStatus, deviceDO.getUseStatus())
                .eq(DeviceDO::getId, deviceDO.getId()));
    }

}
